package com.paradox.aggregation.consumer.rabbit;

import com.paradox.aggregation.providerAPI.config.MessageVo;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class RabbitListeners {

    @RabbitListener(queues="topic.queue1")
    public void queue1(@Payload MessageVo obj, Channel channel, @Headers Map<String,Object> headers) throws IOException, InterruptedException {
        long deliveryTag = (Long)headers.get(AmqpHeaders.DELIVERY_TAG);
        String msgId = (String) headers.get("spring_returned_message_correlation");
        System.out.println("msgId:"+msgId);
        Thread.sleep(10000);
        //channel.basicAck(deliveryTag,false);
        channel.basicNack(deliveryTag,false,true);
        System.out.println(obj);
    }
}
